<template>
  <div>
    <!-- biaoti -->
    <div>研发管理
      <el-button type="primary" style="margin-left: 90%;" @click="tiao">研发申报</el-button>
    </div>
    <!-- 、顶部导航栏 -->
    <div>
      <div>
        <el-tabs>
          <el-tab-pane label="全部" name="first" style="margin-top: 20px;width: 100%;">
            <span>
              预计人数：
            </span>
            <el-input v-model="estimatedHeadCount" style="width: 200px;"></el-input>
            <span>
              城市：
            </span>
            <el-input v-model="rdCity" style="width: 200px;"></el-input>
            <span>
              类型：
            </span>
            <el-input v-model="rdType" style="width: 200px;"></el-input>
            <el-button type="primary" @click="requestFormInquiry()
              ">搜索</el-button>
            <!-- <span>举办城市：</span>
            <el-cascader :options="options">
              <template slot-scope="{ node, data }">
                <span>{{ data.label }}</span>
                <span v-if="!node.isLeaf"> ({{ data.children.length }}) </span>
              </template>
</el-cascader>
<span>项目类型：</span>
<el-cascader :props="props"></el-cascader>
<div style="background-color: rgb(229, 229, 229); height: 100px; width: 100%; display: flex;">
  <div style="height: 80px; width: 22%; background-color: rgb(255, 255, 255);margin-left: 2%; margin-top: 10px;">
    <div style="margin-top: 20px;">
      <div>成本总量</div>
      <div>255</div>
    </div>
  </div>
  <div style="height: 80px; width: 22%; background-color: rgb(255, 255, 255);margin-left: 2%; margin-top: 10px;">
    <div style="margin-top: 20px;">
      <div>筹备中的项目</div>
      <div>255</div>
    </div>
  </div>
  <div style="height: 80px; width: 22%; background-color:rgb(255, 255, 255);margin-left: 2%; margin-top: 10px;">
    <div style="margin-top: 20px;">
      <div>审批中的项目</div>
      <div>255</div>
    </div>
  </div>
  <div style="height: 80px; width: 22%; background-color: rgb(255, 255, 255);margin-left: 2%; margin-top: 10px;">
    <div style="margin-top: 20px;">
      <div>已结束的项目</div>
      <div>054</div>
    </div>
  </div>
</div> -->

            <template>
              <el-table :data="totalCount" style="width: 100%">
                <el-table-column type="selection" fixed="left" />
                <el-table-column prop="projectName" label="项目名称" width="">
                </el-table-column>
                <!-- <el-table-column prop="address" label="负责人">
                </el-table-column> -->
                <el-table-column prop="urgencyLevel" label="紧急程度">
                </el-table-column>
                <el-table-column prop="researchDevelopment" label="研发日期">
                </el-table-column>
                <el-table-column prop="estimatedHeadCount" label="预计人数">
                </el-table-column>
                <el-table-column prop="rdCity" label="城市">
                </el-table-column>
                <el-table-column prop="detailedAddress" label="详细地址">
                </el-table-column>
                <el-table-column prop="rdType" label="研发类型">
                </el-table-column>
                <el-table-column prop="rdProgress" label="研发进度">
                </el-table-column>
                <el-table-column prop="rdCost" label="研发成本总计">
                </el-table-column>
                <el-table-column prop="address" label="操作">
                  <template slot-scope="scope">
                    <el-button type="primary" @click="update(scope.row)" icon="el-icon-edit" circle></el-button>
                    <el-button type="primary" icon="el-icon-delete" @click="open(scope.row)" circle></el-button>
                  </template>

                </el-table-column>
              </el-table>
            </template>
            <el-dialog title="研发管理" :visible.sync="dialogFormVisible">
              <el-form :model="form">
                <el-form-item label="项目名称" :label-width="formLabelWidth">
                  <el-input v-model="form.projectName" autocomplete="off"></el-input>
                </el-form-item>
                <!-- <el-form-item label="负责人" :label-width="formLabelWidth">
                  <el-input v-model="form.name" autocomplete="off"></el-input>
                </el-form-item> -->
                <el-form-item label="紧急程度" :label-width="formLabelWidth">
                  <el-input v-model="form.urgencyLevel" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="研发日期" :label-width="formLabelWidth">
                  <el-input v-model="form.researchDevelopment" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="预计人数" :label-width="formLabelWidth">
                  <el-input v-model="form.estimatedHeadCount" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="城市" :label-width="formLabelWidth">
                  <el-input v-model="form.rdCity" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="详细地址" :label-width="formLabelWidth">
                  <el-input v-model="form.detailedAddress" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="研发类型" :label-width="formLabelWidth">
                  <el-input v-model="form.rdType" autocomplete="off"></el-input>
                </el-form-item>
                <!-- <el-form-item label="研发进度" :label-width="formLabelWidth">
                  <el-input v-model="form.rdProgress" autocomplete="off"></el-input>
                </el-form-item> -->
                <el-form-item label="研发总成本" :label-width="formLabelWidth">
                  <el-input v-model="form.rdCost" autocomplete="off"></el-input>
                </el-form-item>

              </el-form>
              <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible = false">取 消</el-button>
                <el-button type="primary" @click="updateres(projectName)">确 定</el-button>
              </div>
            </el-dialog>

            <div>
              <div class="block">
                <span class="demonstration">完整功能</span>
                <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                  :current-page="currentPage4" :page-sizes="[ 3, 7, 9,15]" :page-size="100"
                  layout="total, sizes, prev, pager, next, jumper" :total="total">
                </el-pagination>
              </div>
            </div>
          </el-tab-pane>
        </el-tabs>
      </div>
    </div>
  </div>
</template>

<script>
import moment from 'moment';
import { requestFormInquiry, deleteres, updateres } from '../../../api/research'
export default {
  mounted() {
    this.label
    this.requestFormInquiry()
  },
  methods: {
    update(row) {
      this.dialogFormVisible = true;
      console.log(row)
      this.form.researchId = row.researchId;
      this.form.projectName = row.projectName;
      this.form.urgencyLevel = row.urgencyLevel;
      this.form.researchDevelopment = row.researchDevelopment;
      this.form.estimatedHeadCount = row.estimatedHeadCount;
      this.form.rdCity = row.rdCity;
      this.form.detailedAddress = row.detailedAddress;
      this.form.rdType = row.rdType;
      this.form.rdProgress = row.rdProgress;
      this.form.rdCost = row.rdCost;
    },
    updateres() {
      updateres(this.form).then(res => {
        console.log(this.form);
        if (res.code === 200) {
          this.requestFormInquiry();
          this.dialogFormVisible = false;
         if (res.code == 200) {
              this.requestFormInquiry();
              this.$message.success(res.message)
            } else {
              this.$message.error(res.message)
            }
          this.dialogFormVisible = false;
        }
      })
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.index = val
      this.requestFormInquiry()
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.page = val
      this.requestFormInquiry()
    },
    requestFormInquiry() {

      const research = {
        page: this.page,
        index: this.index,
        estimatedHeadCount: this.estimatedHeadCount,
        rdCity: this.rdCity !== null && this.rdCity !== '' ? this.rdCity : null,
        rdType: this.rdType !== null && this.rdType !== '' ? this.rdType : null
      }

      console.log(research);
      requestFormInquiry(research).then(res => {
        console.log(res);
        this.tableData = res.result;
        this.total = this.tableData[0];
        this.totalCount = this.tableData[1];
        console.log(this.total);
      }).catch(error => {
        console.error('请求失败', error);
        this.$message.error('请求数据失败: ' + error.message);
      });
    },

    tiao() {
      this.$router.push("/charts/zxinjia")
    },
    open(row) {
      // console.log(row.researchId)
      let researchId = {
        researchId: row.researchId
      }

      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          deleteres(researchId).then(res => {
            // console.log(researchId);
            console.log(res);
            if (res.code == 200) {
              this.requestFormInquiry();
              this.$message.success(res.message)
            } else {this.$message.error(res.message)}
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
    },


  },
  data() {
    return {
      estimatedHeadCount: '',
      rdCity: null,
      rdType: null,
      total: 0,
      totalCount: '',
      page: 1, // 默认页码
      index: 3,
      currentPage4: 4,
      tableData: [],
      dialogFormVisible: false,
      form: {
        projectName: '',
        urgencyLevel: '',
        researchDevelopment: '',
        estimatedHeadCount: '',
        rdCity: '',
        detailedAddress: '',
        rdType: '',
        rdProgress: '',
        rdCost: '',
      },
      formLabelWidth: '100px'
    }
  },

}
</script>
<style scoped></style>
